package com.google.code.swingonfire.component.calendar;

import java.util.Calendar;

public class JCalendarUtils
{

    public static int compare(Calendar a, Calendar b, int field)
    {
        if (a.get(Calendar.YEAR) < b.get(Calendar.YEAR))
        {
            return -1;
        }

        if (a.get(Calendar.YEAR) > b.get(Calendar.YEAR))
        {
            return 1;
        }

        if (field == Calendar.YEAR)
        {
            return 0;
        }

        if (a.get(Calendar.MONTH) < b.get(Calendar.MONTH))
        {
            return -1;
        }

        if (a.get(Calendar.MONTH) > b.get(Calendar.MONTH))
        {
            return 1;
        }

        if (field == Calendar.MONTH)
        {
            return 0;
        }

        if (a.get(Calendar.DAY_OF_MONTH) < b.get(Calendar.DAY_OF_MONTH))
        {
            return -1;
        }

        if (a.get(Calendar.DAY_OF_MONTH) > b.get(Calendar.DAY_OF_MONTH))
        {
            return 1;
        }

        if (field == Calendar.DAY_OF_MONTH)
        {
            return 0;
        }

        throw new IllegalArgumentException("Field not supported: " + field);
    }
}
